package com.wangyadong.hobby.front.model;

import com.wangyadong.hobby.common.BasicModel;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;


import javax.annotation.PostConstruct;
import java.beans.ConstructorProperties;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

/***
 * 构造注入,工厂方法,set注入，afterPropertiesSet，global init， @PostConstruct
 */
public class WuserInfo extends BasicModel implements InitializingBean, DisposableBean, BeanNameAware, BeanFactoryAware, ApplicationContextAware {
    private static final AtomicInteger integer = new AtomicInteger(1);

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(" setApplicationContext>> " + applicationContext.getClass().getSimpleName() + "  " + integer.getAndIncrement());
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println(" setBeanFactory>> " + beanFactory.getClass().getSimpleName() + "  " + integer.getAndIncrement());
    }

    @Override
    public void setBeanName(String s) {
        System.out.println(" setBeanName>> " + s + "  " + integer.getAndIncrement());
    }

    public void init1() {
        System.out.println(" XML初始化方式>> " + integer.getAndIncrement());
    }

    //    @PostConstruct
    public void init2() {
        System.out.println(" 注解初始化方式 " + integer.getAndIncrement());
    }

    public void init() {
        System.out.println(" 全局初始化方式 ========================================= " + integer.getAndIncrement());
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(" IMPL InitializingBean初始化方式 " + integer.getAndIncrement());
    }

    @ConstructorProperties({"isType", "isUserName"})
    public WuserInfo(Byte type, String userName) {
        this.type = type;
        this.userName = userName;
        System.out.println("构造注入 ========================================= " + integer.getAndIncrement());
    }

    public static WuserInfo factoryBeanMethodTestBywyd() {
        System.out.println("工厂注入 ======== " + integer.getAndIncrement() /*+ "  type-> " + type + "  name" + name*/);
        return new WuserInfo();
    }


    public void setInnerClass(InnerClass innerClass) {
        this.innerClass = innerClass;
        System.out.println("setter注入 ========================================= " + integer.getAndIncrement());
    }

    @Override
    public void destroy() throws Exception {

    }

    public WuserInfo(byte type, String userName) {
        this.type = type;
        this.userName = userName;
    }

    private WemailRecord record;
    private InnerClass innerClass;

    public WuserInfo() {
    }

    public InnerClass getInnerClass() {
        return innerClass;
    }

    public void setEmai(String emai) {
        this.emai = emai == null ? null : emai.trim();
//        System.out.println("setter注入 ========================================= " + integer.getAndIncrement());
    }

    public WemailRecord getRecord() {
        return record;
    }

    public void setRecord(WemailRecord record) {
        this.record = record;
    }

    public static class InnerClass {
        private String name = "inner Class";

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    private String userName;

    private String password;

    private String emai;

    private Byte type;

    private Date createDate;

    private Byte source;

    private String phone;

    public WuserInfo(WemailRecord record) {
        this.record = record;
    }


    public String getUserName() {
        return userName;
    }

    //    @Required
    public void setUserName(String userName) {
        this.userName = userName == null ? null : userName.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    public String getEmai() {
        return emai;
    }


    public Byte getType() {
        return type;
    }

    public void setType(Byte type) {
        this.type = type;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Byte getSource() {
        return source;
    }

    public void setSource(Byte source) {
        this.source = source;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? null : phone.trim();
    }

    public static void aspectOf(){
        System.out.println("aspectOf ========================================= " + integer.getAndIncrement());
    }

}
